<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table style="width:100%;">
	        <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/call_tariff_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="openSetBasic()">添加</a>
	                </sec:authorize>
	                <sec:authorize url='/call_tariff_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>  
	                </sec:authorize>
	                <sec:authorize url='/call_tariff_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">批量删除</a>  
	                </sec:authorize>
<!-- 	                <a class="mini-button" iconCls="icon-download" onclick="exportData()">导出当前</a> -->
<!-- 		            <a class="mini-button" iconCls="icon-download" onclick="exportData()">导出全部</a>     -->
	            </td>
	           <td style="white-space:nowrap;">
	            	标题（模糊）：<input id="condition1" emptyText="请输入标题名" class="mini-textbox" style="width: 170px"/>
	            	中继（模糊）：<input id="condition2" emptyText="请输入中继名" class="mini-textbox" style="width: 170px"/>
	            	<a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
	            </td>
	        </tr>
	    </table>
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid" allowCellWrap="true" multiSelect="true" idField="id" pageSize="20" url="call_tariff_list.do" style="width:100%;height:100%;">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn" ></div>
			<div field="title" width="20%" headerAlign="center" align="center">标题</div>
			<div field="relayName" width="10%" headerAlign="center" align="center">中继</div>
			<div field="typeValue" width="10%" headerAlign="center" align="center">呼叫类型</div>
			<div field="basicFee" width="10%" headerAlign="center" align="center">基本资费（元）</div>
			<div field="startime" width="10%" headerAlign="center" align="center">起步时长</div>
			<div field="preferentiaTitle" width="15%" headerAlign="center" align="center">优惠方案</div>
			<div field="remark" width="15%" headerAlign="center" align="center">说明</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function search() {
	var c1 = mini.get("condition1").getFormValue();
	var c2 = mini.get("condition2").getFormValue();
	grid.load({ title:c1,relayTitle:c2});
}

//导出全部
function exportData() {
	location.href="my_remind_export.do";
}

//导出当前页数据
function exportCurrentData() {
	var data =grid.getData();
	var ids = [];
	$.each(data , function(){
        ids.push(this.id);
    });
	 var id = ids.join(',');
	 location.href="my_remind_current_export.do?ids=" +id;
}

//新建
function openSetBasic() {
	mini.open({
        url: "call_tariff_add.do",
        allowResize:false,
        title: "新增资费设置", width: 460, height: 350,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
        	}
        }
    });
}

//删除
function remove() {
	var rows = grid.getSelecteds();
	if (rows.length > 0) {
		mini.confirm("确定删除选中记录？", "删除",
	          function (action) {
	              if (action == "ok") {
	            	var arr = new Array();
	          		$.each(rows,function(i,v){
	          			arr.push(v.id);
	          		});
	          		var rids = arr.join("-");
	                  $.post(
	                  	"call_tariff_del.do",{id:rids},function(data){
	                  		if(data.success){
	                  			mini.showMessageBox({
	                               title: "提示",
	                               showModal:false,
	                               iconCls: "mini-messagebox-info",
	                               message: "已删除！",
	                               timeout: 3000,
	                               x: 'right',
	                               y: 'bottom'
	                           });
	                  		grid.reload();
	                  		}else{
	                  			mini.alert("数据错误！");
	                  		}
	                  	},"json");
	              }
	          });
    } else {
    	mini.alert("请选中一条记录");
    }
}

//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "call_tariff_edit.do",
            allowResize:false,
            title: "修改资费设置", width: 460, height: 350,
            onload: function () {
                var iframe = this.getIFrameEl();
                iframe.contentWindow.SetData(row[0]);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "修改成功！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
                	grid.reload();
            	}
            }
        });
        
    } else {
    	mini.alert("请选中一条记录");
    }
    
}
</script>
</body>
</html>